﻿<%@ Page Title="" Language="C#" MasterPageFile="~/Content/Master.Master" Inherits="System.Web.Mvc.ViewPage<SCS.Core.Models.Collection.StockCollection>" %>
<%@ Import Namespace="SCS.Core" %>
<%@ Import Namespace="SCS.Core.Models" %>
<%@ Import Namespace="SCS.Core.ViewModels" %>
<%@ Import Namespace="SCS.Core.Controllers" %>
<%@ Import Namespace="SCSService" %>
<asp:Content ID="Content1" ContentPlaceHolderID="TitleContent" runat="server">
	Chi tiết kho
</asp:Content>

<asp:Content ID="Content2" ContentPlaceHolderID="MainContent" runat="server">

    <link rel="stylesheet" type="text/css" href="/Content/smoothness-1.8.13/jquery-ui-1.8.13.custom.css">
    <link rel="stylesheet" type="text/css" href="/Content/smoothness-1.8.13/ui.dropdownchecklist.themeroller.css">
    <script type="text/javascript" src="/Scripts/jquery-1.6.1.min.js"></script>
    <script type="text/javascript" src="/Scripts/jquery-ui-1.8.13.custom.min.js"></script>
    <script type="text/javascript" src="/Scripts/ui.dropdownchecklist-1.4-min.js"></script>
    <script src="/Scripts/jquery.selectboxes.min.js" type="text/javascript"></script>
    <script type="text/javascript" src="<%: Url.Content("~/Scripts/MicrosoftAjax.js") %>"></script>
   <%--Validator--%>
    <script src="/Scripts/jquery.validate.min.js" type="text/javascript"></script>
    <script src="/Scripts/MicrosoftMvcJQueryValidation.js" type="text/javascript"></script>
     <script type="text/javascript">
     var HttpRequest = false;

     if (window.XMLHttpRequest) // Internet Explorer
     {
         HttpRequest = new XMLHttpRequest();
     }
     else  // Other browsers  
     {
         HttpRequest = new ActiveXObject("Microsoft.XMLHTTP");
     }
 

          function getValuetextBox(StockID) {

              var DivTxtBox = document.getElementById("lsttxtBox")
              var StringHTML = '<table> <tr class="display"><td align=center>  Serial</td><td align="center" >Code</td></tr> ';
              if (!HttpRequest) return;
              if (StockID < 1) return;

              var url = '<%=Url.Action("AjaxServer","Stock")%>' + '/' + StockID;
  
              HttpRequest.open("GET", url);
              HttpRequest.onreadystatechange = function () {
                  if (HttpRequest.readyState == 4 && HttpRequest.status == 200) {
                      var xml = HttpRequest.responseXML;
                      var c = xml.getElementsByTagName("ProStockDetail");


                      for (i = 0; i < c.length; i++) {
                          var id = c[i].attributes[0].value;
                          var Serial = c[i].firstChild.nodeValue;
                          var Code = c[i].lastChild.nodeValue; ;
                          StringHTML = StringHTML + '<tr> <td> <input id=txtSerial' + id + ' name=txtSerial' + id + ' value=' + Serial + '  type="text" class="form-field" style="width:200px" /></td> <td> ' + ' <input type="text" class="form-field" style="width:200px" id=txtCode' + id + ' value=' + Code + ' name=txtCode' + id + '  /></td><td><div class="button themed" onclick ="AjaxSaveEdit(' + id + ')"> Save </div> </td> </tr> ';
                      }
                      StringHTML = StringHTML + ' </table>';
                      DivTxtBox.innerHTML = StringHTML;
                  }
              }
              HttpRequest.send(null);
          }

         
        
    </script>

         
    <script type="text/javascript">
        function CreatextBox() {
            var count = document.getElementById("Quantity").value;
            var DivTxtBox = document.getElementById("lsttxtBox")
            var string = '<table> <tr class="display"><td align=center>  Serial</td><td align="center" >Code</td></tr> ';
            if (count > 0) {
                for (i = 0; i < count; i++) {
                    string = string + '<tr> <td> <input id=txtSerial' + i + ' name=txtSerial' + i + ' type="text" class="form-field hafl" /></td> <td> ' + ' <input type="text" class="form-field hafl" id=txtCode' + i + ' name=txtCode' + i + '  /></td> </tr> '

                }
                string = string + ' </table>';
                DivTxtBox.innerHTML = string;
            }
            else {
                DivTxtBox.innerHTML = "";
            }

        }
    
    </script>
     <script type="text/javascript">
         $(function () {
             $("#StockIn").datepicker({ dateFormat: 'dd/mm/yy' });
             $("#ModifyDate").datepicker({ dateFormat: 'dd/mm/yy' });

            var isAdd="<%=ViewData["IsAdd"]!=null?(bool)ViewData["IsAdd"]:true %>";
            if(isAdd==='True')
            {
                //them moi
                $("#Quantity").keypress(function(){
                    CreatextBox();
                });
                $("#Quantity").keyup(function(){
                    CreatextBox();
                });

            }
            else if(isAdd==='False')
            {
                //edit
                //$("#Quantity").load(function(){
                    getValuetextBox(<% =Model.StockID.ToString() %>);
                //});
            }
         });
         
	</script>
    
    <% Html.EnableClientValidation(); %>
   <% using (Html.BeginForm((bool)ViewData["IsAdd"] ? "SaveAddStock" : "SaveEditStock", "Stock", FormMethod.Post, new { siteGuid = "sendFileForm", language = "sendFileForm", id = "sendFileForm", enctype = "multipart/form-data" }))
            {
          %>
     
     <div class="clear"></div>
       
        <div class="box ">
		    <h2 class="box-header"><%=(bool)ViewData["IsAdd"] ? "Import" : "Edit Stock" %></h2>
		    <div class="box-content">

                <label class="form-label"> Số lượng </label>
                <% string sty = "";
                   if((bool)ViewData["IsAdd"])
                   {
                       %>
                        <%= Html.TextBoxFor(m => m.Quantity, new { @class = "form-field small"})%>
                       <%
                   }
                   else
                   {
                    //sty = "readonly";
                       %>
                       <%= Html.TextBoxFor(m => m.Quantity, new { @class = "form-field small"})%>
                       <%
                   }
                   %>
                
                 
                <span style="color:Red;font-weight:bold"><%= Html.ValidationMessageFor(m => m.Quantity) %></span>
              
                <div id="lsttxtBox" style="visibility:hidden; width:0px; height:0px;"></div>

                 <label class="form-label"> Ngày nhập </label>
                 
                 <%=Html.TextBoxFor(m => m.StockIn, new { @class = "form-field datepicker"})%> <span style="color:Red;font-weight:bold"> <%= Html.ValidationMessageFor(m => m.StockIn)%> </span>

                  <label class="form-label"> Ngày cập nhật </label>
                 <%=Html.TextBoxFor(m=>m.ModifyDate,new { @class = "form-field datepicker"}) %>
                
                 <label class="form-label"> Ghi chú </label>
                 <%= Html.TextAreaFor(m => m.NotesStock, new { @class = "form-field half" })%>
                                                    
                 <label class="form-label"> Mã </label>
                 <%=Html.TextBoxFor(m=>m.StockCode,new { @class = "form-field small" }) %>
                 
                 <label class="form-label"> Kích hoạt </label>
                 <%if (Model.Status == true)
                   {
                   %>
                        <%=Html.CheckBox("Status", true)%> Kích hoạt
                  <%   }
                   else
                   {
                       if ((bool)ViewData["IsAdd"])
                       {
                       %>
                        <%=Html.CheckBox("Status", true)%> Kích hoạt
                       <%
                       }
                       else
                       { 
                       %>
                        <%=Html.CheckBox("Status", false)%> Kích hoạt
                       <%
                       }
                    
                   } 
                    %>

                 <%=Html.TextBoxFor(m => m.StockID, new {@Style="display:none" })%>

                 <%=Html.TextBoxFor(m=>m.ProductID,new {@Style="display:none"}) %>
                
                 <p>
                <%=ViewData["Result"]%>
                </p>
                    
                  <input type="submit" value="" class="button white_input save_input " style="width: 74px;height: 28px; float:left; margin-right:10px;"/> <!--Button Save-->
                  <a class="button white" href="javascript:history.back();"><span class="icon_text cancel"></span>Đóng</a> <!--Button Close-->
                 
	        </div>
	    </div>
        <div class="clear"></div>
    
    
    <% } %>

<script type="text/javascript">
    var HttpRequest = false;

    if (window.XMLHttpRequest) // Internet Explorer
    {
        HttpRequest = new XMLHttpRequest();
    }
    else  // Other browsers  
    {
        HttpRequest = new ActiveXObject("Microsoft.XMLHTTP");
    }


    function AjaxSaveEdit(id) {
        if (!HttpRequest) return;
        if (id < 0) return;
        var code = document.getElementById("txtCode" + id).value;
        var serial = document.getElementById("txtSerial" + id).value;
        var url = '<%=Url.Action("AjaxEditCodeSerial","Stock")%>' + '/' + id + '?code=' + code + '&serial=' + serial;

        HttpRequest.open("POST", url);
        HttpRequest.onreadystatechange = function () {
            if (HttpRequest.readyState == 4 && HttpRequest.status == 200) {
                alert("Sửa không thành công!");
                return;
            }
            
        }
        alert("Sửa thành công!");
        HttpRequest.send(null);
    }


        
    </script>
</asp:Content>
